import 'package:flutter/material.dart';

class DeleteListChipDemo extends StatefulWidget {
  const DeleteListChipDemo({Key? key}) : super(key: key);

  @override
  _DeleteListChipDemoState createState() => _DeleteListChipDemoState();
}

class _DeleteListChipDemoState extends State<DeleteListChipDemo> {
  List<String> _list = ["Apple", "Banana", "Lemon"];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("带删除功能的列表"),
      ),
      body: Container(
        child: Center(
          child: Wrap(
            spacing: 8,
            runSpacing: 8,
            children: _list.map((tag) {
              return Chip(
                label: Text(tag),
                onDeleted: () {
                  setState(() {
                    _list.remove(tag);
                  });
                },
              );
            }).toList(),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            _list = ["Apple", "Banana", "Lemon"];
          });
        },
        child: Icon(Icons.restore),
      ),
    );
  }
}
